package com.ruoyi.foodworks.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.foodworks.domain.ReplyLikeRequest;
import com.ruoyi.foodworks.service.ReplyLikeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 回复点赞Controller
 * 
 * @author ruoyi
 * @date 2024-01-01
 */
@RestController
@RequestMapping("/foodworks/reply-likes")
public class ReplyLikeController extends BaseController {
    
    @Autowired
    private ReplyLikeService replyLikeService;
    
    /**
     * 回复点赞/取消点赞
     */
    @Log(title = "回复点赞", businessType = BusinessType.UPDATE)
    @PostMapping("/like")
    public AjaxResult likeReply(@RequestBody ReplyLikeRequest request) {
        Map<String, Object> result = replyLikeService.likeReply(request);
        return AjaxResult.success(result);
    }
    
    /**
     * 获取回复点赞状态
     */
    @GetMapping("/status")
    public AjaxResult getReplyLikeStatus(
            @RequestParam List<Long> replyIds,
            @RequestParam Long userId) {
        Map<Long, Boolean> likeStatusMap = replyLikeService.getReplyLikeStatus(replyIds, userId);
        return AjaxResult.success(likeStatusMap);
    }
    
    /**
     * 获取回复点赞数
     */
    @GetMapping("/counts")
    public AjaxResult getReplyLikeCounts(@RequestParam List<Long> replyIds) {
        Map<Long, Integer> likeCountMap = replyLikeService.getReplyLikeCounts(replyIds);
        return AjaxResult.success(likeCountMap);
    }
}
